<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Utility {
	var $CI;
	public function __construct() {
		$this->CI = & get_instance();
	}
	/**
	 * 封装发送邮件
	 * @param string 发送者  $from
	 * @param string 接收者 $to
	 * @param string 标题 $subject
	 * @param string 内容 $body
	 * @author michael yeh
	 */
	 public function send_mail($from, $to, $subject, $body) {
		
		$this->CI->load->library('email');
		$this->CI->email->initialize($this->CI->config->item('email'));
		$this->CI->email->from($from);
		$this->CI->email->to($to);
		$this->CI->email->subject($subject);
		$this->CI->email->message($body);
		$this->CI->email->send();
	}
	
	/**
	 * 生成验证码
	 * @param string $word
	 * @param string $path
	 * @author michael yeh
	 */
	public function captcha($word = null) {
		$this->CI->load->helper('captcha');
		$vals = array(
		    'word' => $word,
		    'img_path' => './img/captcha/',
		    'img_url' => $this->CI->config->item('base_url') . '/img/captcha/',
		    'img_width' => '150',
		    'img_height' => 30,
		    'expiration' => 7200
		    );
		
		$cap = create_captcha($vals);
		//print_r($cap);
		$_SESSION['captcha'] = $cap['word'];
		return $cap;
	}
}